/**
 * Created by zhanshen886 on 2019/1/21.
 */
/**
 * Created by zhanshen886 on 2019/1/18.
 */
function Animator(duration, progress) {
    this.duration = duration;
    this.progress = progress;
    this.next = true;
}
Animator.prototype = {
    constructor: Animator,
    start: function (finished) {
        var startTime = new Date().getTime();
        var duration = this.duration, self = this, timeOut = 0;
        var vendors = ["webkit", "moz"];
        for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) {
            window.requestAnimationFrame = window[vendors[i] + "RequestAnimationFrame"];
        }
        if (!window.requestAnimationFrame) {
            window.requestAnimationFrame = function (callback, element) {
                var start = 0, finish = 0;
                window.setTimeout(function () {
                    start = +new Date();
                    callback(start);
                    finish = +new Date();
                    timeOut = 1000 / 300 - (finish - start);
                }, timeOut);
            };
        }
        window.requestAnimationFrame(function step() {
            var p = (new Date().getTime() - startTime) / duration;
            //var y = p * p * p;
            self.progress(p, p);
            if (p >= 1.0) {
                self.progress(1.0, 1.0);
                self.next = false;
                finished();
            }
            if (self.next) window.requestAnimationFrame(step);
        });
    },
    stop: function () {
        this.next = false;
    }
};
var code = Epg.getParam("code", "ggly_iptv_animation");
CONFIG.COLUMN_CODE = code;
var uri = "column/secondPage/secondPage" + CONFIG.EXT + "?1=1&code=" + code;
var SecondPage = {
    userid: Epg.cookie.get("userid"),
    role: Epg.cookie.get("role"),
    orderType: Epg.cookie.get("orderType"),
    side_idx: Epg.getParamInt("side_idx", "0"),							// 侧边栏菜单项隐藏了多少个
    sidePrevButtonId: Epg.getParam("sidePrevButtonId", "side_0"),		// 侧边栏离开时的id
    navPrevButtonId: Epg.getParam("navPrevButtonId", ""),				// 菜单离开时的id
    recommendPrevButtonId: Epg.getParam("recommendPrevButtonId", ""),	// 推荐位离开时的id
    carousel_index: Epg.getParamInt("carousel_index", 1),				// 大推荐位滚屏到第几屏了

    sideClick: function () {												// 侧边栏点击事件
        if (SecondPage.sidePrevButtonId === Epg.btn.current.id) return;
        SecondPage.sidePrevButtonId = Epg.btn.current.id;
        //SecondPage.updateSideBg();										// 更新侧边栏菜单项背景图
        SecondPage.init();												// 初始化推荐位信息
    },
    sideBeforeMove: function (dir, current) {							// 侧边栏移动前判断事件
        if ("right" === dir) {
            //SecondPage.sidePrevButtonId = current.id;
            if (SecondPage.recommendPrevButtonId !== "") {
                Epg.btn.set(SecondPage.recommendPrevButtonId);
            } else if (Epg.btn.get("label_recommend_0")) {
                Epg.btn.set("label_recommend_0");
            } else {
                Epg.btn.set("recommend_big");
            }
            return false;
        } else if ("up" === dir && !(current.up && current.up.length > 0)) {
            Epg.btn.set(SecondPage.navPrevButtonId || 'nav_' + navs2[code][0]);
            return false;
        }
    },
    sideFocusHandler: function (current) {								// 侧边栏菜单项获得焦点
        var index = current.index;
        if (index < SecondPage.side_idx) {
            SecondPage.side_idx = SecondPage.side_idx - (SecondPage.side_idx - index);
            G("sides").scrollTop = 46 * SecondPage.side_idx;			// 向上移动46个像素
        } else if (index > (SecondPage.side_idx + (3 + navs2[code][1] * 2))) {
            SecondPage.side_idx = SecondPage.side_idx + (index - SecondPage.side_idx - (3 + navs2[code][1] * 2));
            G("sides").scrollTop = 46 * SecondPage.side_idx;			// 向下移动46个像素
        }
        G("side_more").style.visibility = (SecondPage.side_idx + 3 + navs2[code][1] * 2) < groups[1].metadatas.length ? 'visible' : 'hidden';
    },
    updateSideBg: function () {											// 更新侧边栏菜单项背景颜色
        var side = parseInt((SecondPage.sidePrevButtonId).slice(5));
        var span = document.querySelector("#sides").getElementsByTagName("span");
        Array.prototype.slice.call(span).forEach(function (value, index) {
            if (index === side) {
                Epg.addClass(value, "side_focus");
                value.getElementsByTagName("div")[0].style.color = "#944600";
                value.getElementsByTagName("div")[0].style.fontWeight = "900";
            } else {
                Epg.removeClass(value, "side_focus");
                value.getElementsByTagName("div")[0].style.color = "#FFFFFF";
                value.getElementsByTagName("div")[0].style.fontWeight = "400";
            }
        });
        G("recommend_down").style.visibility = side === groups[1].metadatas.length ? "hidden" : "visible";
    },
    initSide: function (flag, f) {										// 初始化侧边栏
        var val = code.slice(10);							// 截取二级页面关键字作为侧边栏菜单项背景取色
        SecondPage.initButtons();							// 初始化buttons数组
        var metadatas = groups[1].metadatas;				// 获取配置内容第二个数组
        var html = '<div class="sides">';
        var str = [];										// 把侧边栏菜单项值组装在一起，查询点播前5位的视频信息
        html += '<span class="' + val + '"><div id="side_0" class="side_txt">精选推荐</div></span>';
        for (var i = 0, length = metadatas.length; i < length; i++) {
            str.push("'" + metadatas[i].value + "'");
            html += '<span class="' + val + '"><div id="side_' + (i + 1) + '" class="side_txt">' + metadatas[i].label + '</div></span>';
        }
        if ("true" === flag) {
            SecondPage.initDjdak(str.join(","), f);
        }
        html += '</div>';
        G("sides").innerHTML = html;
        G("sides").scrollTop = 46 * SecondPage.side_idx;
        G("side_more").style.visibility = (SecondPage.side_idx + 3 + navs2[code][1] * 2) < length ? 'visible' : 'hidden';	// 更多侧边栏菜单项箭头是否显示
        SecondPage.updateSideBg();
    },
    recommendClick: function () {										// 推荐位点击事件
        SecondPage.updateCurrentUri();
        var id = Epg.btn.current.id;
        if (/^djdak_/.test(id)) {
            SecondPage.isOrder({type: 'recommend_video', code: Epg.btn.current.code});
        } else if ('recommend_big' === id) {
            SecondPage.isOrder({
                type: groups[0].metadatas[SecondPage.carousel_index].type,
                code: groups[0].metadatas[SecondPage.carousel_index].value
            });
        } else if (/^recommend_/.test(id)) {
            SecondPage.isOrder({type: Epg.btn.current.type, code: Epg.btn.current.code});
        } else {
            SecondPage.isOrder({type: 'recommend_series', code: Epg.btn.current.code});
        }
    },
    isOrder: function (recommend) {										// 推荐位等的判断事件
        var type = recommend.type, code = recommend.code;
        if ('album' === type || 'activity' === type) {
            SecondPage.getActivityOrAlbum(code);
        } else if ('recommend_series' === type) {
            Epg.go('column/subSeries/subSeries' + CONFIG.EXT + '?code=' + code);
        } else {
            if ("free" != SecondPage.orderType) {
                Epg.goMP('column/mp/mp' + CONFIG.EXT + '?method=playVideo&code=' + code);
            } else {
                Epg.go('column/order/order' + CONFIG.EXT + '?source=' + CONFIG.COLUMN_CODE + '&code=' + code);
            }
        }
    },
    getActivityOrAlbum: function (code) {								// 进入活动或者专辑页面
        var postData = {'code': code, 'appVersion': CONFIG.APP_VERSION, 'role': SecondPage.role};
        Epg.postAPI('epg/get', postData, function (data) {
            if (data && data.code === 0) {
                Epg.go(data.epg.path);
            }
        });
    },
    recommendBeforeMove: function (dir, current) {						// 推荐位移动前的判断事件
        if ("left" === dir && !(current.left && current.left.length > 0)) {
            SecondPage.recommendPrevButtonId = current.id;
            Epg.btn.set(SecondPage.sidePrevButtonId);
            return false;
        } else if ("up" === dir && !(current.up && current.up.length > 0)) {
            SecondPage.recommendPrevButtonId = current.id;
            Epg.btn.set(Home.ipPrevButtonId || 'tj_type_state_1');
            return false;
        }
    },
    recommendFocusHandler: function () {
        Epg.marquee.start();
        var id = Epg.btn.current.id;
        Epg.addClass(G(id).parentElement, 'label_recommend_scale');
    },
    recommendBlurHandler: function () {
        Epg.marquee.stop();
        var id = Epg.btn.previous.id;
        Epg.removeClass(G(id).parentElement, 'label_recommend_scale');
    },
    marqueeStart: function () {											// 文本进行滚动
        var id = Epg.btn.current.id + '_txt';
        var marqueeParent = G(id);
        var html = Epg.trim(marqueeParent.innerHTML);
        SecondPage.html = html;
        marqueeParent.innerHTML = '<div id="' + id + '_marquee" class="marquee"><div><div>' + html + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div>' + html + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></div></div>';
        var marqueeChild = G(id + '_marquee').getElementsByTagName('div')[0].getElementsByTagName('div')[0];
        var width1 = parseInt(Epg.css(marqueeParent, 'width'));
        var width2 = parseInt(Epg.css(marqueeChild, 'width'));
        if (width1 < width2) {
            //var offsetWidth = marqueeChild.getElementsByTagName('div')[0].offsetWidth;
            function scroll() {
                animator = new Animator(6000, function (p) {
                    if (G(id + '_marquee')) {
                        G(id + '_marquee').scrollLeft = p * width2;
                    }
                });
                animator.start(function () {
                    G(id + '_marquee').scrollLeft = 0;
                    scroll();
                })
            }

            scroll();
        } else {
            G(id).innerHTML = '<div id="' + id + '_marquee" class="marquee"><div><div>' + html + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></div></div>';
        }
    },
    marqueeStop: function () {											// 文本滚动停止
        var id = Epg.btn.previous.id + '_txt';
        animator && animator.stop();
        G(id + '_marquee').scrollLeft = 0;
        G(id).innerHTML = SecondPage.html;
    },
    djdakFocusHandler: function (current) {								// 大家都爱看文本获得焦点
        var id = current.id;
        var name = current.videoName;
        if ("ggly_iptv_song" === CONFIG.COLUMN_CODE) {
            name = current.seriesName;
        }
        G(id + "_txt").innerHTML = name;
        SecondPage.marqueeStart();
    },
    djdakBlurHandler: function (prev) {									// 大家都爱看文本失去焦点
        var id = prev.id;
        SecondPage.marqueeStop();
        var name = prev.seriesName;
        if ("ggly_iptv_song" === CONFIG.COLUMN_CODE) {
            name = prev.videoName;
        }
        G(id + "_txt").innerHTML = name;
    },
    initDjdak: function (label, f) {										// 初始化大家都爱看列表信息
        document.querySelector('.djdak_title').style.backgroundImage = 'url(images/djdak_title.png)';
        document.querySelector(".djdak").style.backgroundImage = 'url(images/djdak_bg.png)';
        Epg.postAPI("tag/get-videoList-byTagType", {"tagCode": label, "topLimit": 5}, function (res) {
            if (res && res.code === 0) {
                var videoList = res.videoList, html = "";
                if ("ggly_iptv_song" === CONFIG.COLUMN_CODE) {
                    for (var i = 0, length = videoList.length; i < length; i++) {
                        html += '<div id="djdak_' + i + '"><div id="djdak_' + i + '_txt" class="djdak_txt">' + videoList[i].name + '</div></div>';
                        buttons.push({
                            id: 'djdak_' + i,
                            code: videoList[i].code,
                            videoName: videoList[i].name,
                            seriesName: videoList[i].intro,
                            action: SecondPage.recommendClick,
                            focusHandler: SecondPage.djdakFocusHandler,
                            blurHandler: SecondPage.djdakBlurHandler,
                            beforeMove: SecondPage.recommendBeforeMove,
                            focusClass: 'djdak',
                            autoDirGroup: 4
                        });
                    }
                } else {
                    for (var i = 0, length = videoList.length; i < length; i++) {
                        html += '<div id="djdak_' + i + '"><div id="djdak_' + i + '_txt" class="djdak_txt">' + videoList[i].intro + '</div></div>';
                        buttons.push({
                            id: 'djdak_' + i,
                            code: videoList[i].code,
                            videoName: videoList[i].name,
                            seriesName: videoList[i].intro,
                            action: SecondPage.recommendClick,
                            focusHandler: SecondPage.djdakFocusHandler,
                            blurHandler: SecondPage.djdakBlurHandler,
                            beforeMove: SecondPage.recommendBeforeMove,
                            focusClass: 'djdak',
                            autoDirGroup: 4
                        });
                    }
                }
                G("djdak").innerHTML = html;
            }
            Epg.autoMakeBtnDir(buttons);
            Epg.btn.init([f, 'recommend_big'], buttons, '', false);
        });
    },
    autoPlay: function () {												// 最大推荐位进行轮播
        SecondPage.carousel_index++;
        SecondPage.carousel_index = SecondPage.carousel_index >= 3 ? 0 : SecondPage.carousel_index;
        var span = G("tj_id1").getElementsByTagName('span');
        var li = G("tj_id1").getElementsByTagName('li');
        Array.prototype.slice.call(span).forEach(function (value, index) {
            value.className = index === SecondPage.carousel_index ? 'recommend_big_show' : '';
        });
        Array.prototype.slice.call(li).forEach(function (value, index) {
            value.className = index === SecondPage.carousel_index ? 'recommend_dian' : '';
        });
    },
    initRecommendBig: function () {										// 初始化大推荐位信息
        //var html = "";
        //
        //html += '</ul>';
        //G("recommend_big").innerHTML = html;
        recommend_big_interval = setInterval(function () {
            SecondPage.autoPlay();
        }, 4000);
    },
    initRecommend: function (ID) {											// 初始化分类信息

    },
    initLabelRecommend: function (ID) {									// 分类下商品列表接口

    },
    initLabelRecommendFail: function () {								// 初始化标签推荐位信息失败处理方法
        var id = Epg.btn.current.id;
        var side = parseInt((SecondPage.sidePrevButtonId).slice(5));
        if ("recommend_down" === id) {
            SecondPage.sidePrevButtonId = "side_" + (side - 1);
        } else {
            SecondPage.sidePrevButtonId = "side_" + (side + 1);
        }
        // 触发侧边栏菜单项获得焦点事件
        Epg.btn.get(SecondPage.sidePrevButtonId).focusHandler({
            id: SecondPage.sidePrevButtonId,
            index: parseInt((SecondPage.sidePrevButtonId).slice(5))
        });
        SecondPage.init();
    },
    navClick: function () {												// 菜单栏点击事件
        SecondPage.updateCurrentUri();
        var code = Epg.btn.current.code;
        if (code === CONFIG.COLUMN_CODE) return;
        if ("ggly_iptv_home" === code) {
            location.href = CONFIG.EPG_PATH + 'column/iptv_home/iptv_home' + CONFIG.EXT + '?f=nav_0';
        } else if ("ggly_iptv_more" === code) {
            location.href = CONFIG.EPG_PATH + 'column/morePage/morePage' + CONFIG.EXT;
        } else if ("ggly_iptv_area" === code) {
            location.href = CONFIG.EPG_PATH + 'column/areaPage/areaPage' + CONFIG.EXT;
        } else if ("nav_order" === code) {
            Epg.go('column/order/order' + CONFIG.EXT);
        } else if ("nav_search" === code) {
            Epg.go('column/search/search' + CONFIG.EXT);
        } else if ("nav_history" === code) {
            Epg.go('column/history/history' + CONFIG.EXT + '?isPlay=true');
        } else if ("nav_fav" === code) {
            Epg.go('column/fav/seriesFav' + CONFIG.EXT + '?isPlay=true');
        } else {
            location.href = CONFIG.EPG_PATH + 'column/secondPage/secondPage' + CONFIG.EXT + '?code=' + code;
        }
    },
    navBeforeMove: function (dir, current) {								// 菜单栏移动前的判断事件
        if ("down" === dir) {
            SecondPage.navPrevButtonId = current.id;
            if (SecondPage.recommendPrevButtonId !== "") {
                Epg.btn.set(SecondPage.recommendPrevButtonId);
            } else if (Epg.btn.get("label_recommend_0")) {
                Epg.btn.set("label_recommend_0");
            } else {
                Epg.btn.set("recommend_big");
            }
            return false;
        }
    },
    recommendUpOrDownFocusHandler: function () {							// 推荐位上下翻页箭头获得焦点事件
        var id = Epg.btn.current.id;
        var side = parseInt((SecondPage.sidePrevButtonId).slice(5));
        if ("recommend_down" === id) {
            SecondPage.sidePrevButtonId = "side_" + (side + 1);
        } else {
            SecondPage.sidePrevButtonId = "side_" + (side - 1);
        }
        // 触发侧边栏菜单项获得焦点事件
        Epg.btn.get(SecondPage.sidePrevButtonId).focusHandler({
            id: SecondPage.sidePrevButtonId,
            index: parseInt((SecondPage.sidePrevButtonId).slice(5))
        });
        SecondPage.init();
    },
    initButtons: function () {											// 初始化光标按钮事件
        buttons = [
            {
                id: 'nav_order',
                code: 'nav_order',
                left: ['nav_7'],
                action: SecondPage.navClick,
                beforeMove: SecondPage.navBeforeMove,
                focusClass: 'nav_order',
                autoDirGroup: 1
            },
            {
                id: 'nav_search',
                code: 'nav_search',
                action: SecondPage.navClick,
                beforeMove: SecondPage.navBeforeMove,
                focusClass: 'nav_search',
                autoDirGroup: 1
            },
            {
                id: 'nav_history',
                code: 'nav_history',
                action: SecondPage.navClick,
                beforeMove: SecondPage.navBeforeMove,
                focusClass: 'nav_history',
                autoDirGroup: 1
            },
            {
                id: 'nav_fav',
                code: 'nav_fav',
                action: SecondPage.navClick,
                beforeMove: SecondPage.navBeforeMove,
                focusClass: 'nav_fav',
                autoDirGroup: 1
            },
            {
                id: 'recommend_big',
                action: SecondPage.recommendClick,
                beforeMove: SecondPage.recommendBeforeMove,
                focusClass: 'recommend_big',
                autoDirGroup: 4
            },
            {id: 'recommend_up', focusHandler: SecondPage.recommendUpOrDownFocusHandler, autoDirGroup: false},
            {id: 'recommend_down', focusHandler: SecondPage.recommendUpOrDownFocusHandler, autoDirGroup: false}
        ];
        for (var i = 0, length = navs.length; i < length; i++) {
            buttons.push({
                id: 'nav_' + i,
                code: navs[i],
                right: i === 7 ? ['nav_order'] : '',
                action: SecondPage.navClick,
                beforeMove: SecondPage.navBeforeMove,
                focusClass: 'nav',
                autoDirGroup: 2
            });
        }
        buttons.push({
            id: 'side_0',
            index: 0,
            action: SecondPage.sideClick,
            beforeMove: SecondPage.sideBeforeMove,
            focusHandler: SecondPage.sideFocusHandler,
            focusClass: 'side',
            autoDirGroup: 3
        });
        for (var i = 0, length = groups[1].metadatas.length; i < length; i++) {
            buttons.push({
                id: 'side_' + (i + 1),
                index: (i + 1),
                value: groups[1].metadatas[i].value,
                action: SecondPage.sideClick,
                beforeMove: SecondPage.sideBeforeMove,
                focusHandler: SecondPage.sideFocusHandler,
                focusClass: 'side',
                autoDirGroup: 3
            });
        }
    },

    updateCurrentUri: function () {
        CONFIG.CURRENT_URI = uri + '&side_idx=' + SecondPage.side_idx + '&sidePrevButtonId=' + SecondPage.sidePrevButtonId + '&navPrevButtonId=' + SecondPage.navPrevButtonId +
            '&recommendPrevButtonId=' + SecondPage.recommendPrevButtonId + '&carousel_index=' + SecondPage.carousel_index;
    }
};
var isEnableButton = false;						// 标识按钮是否生效,用于视频初始化时防止按钮点击生效

CONFIG.COLUMN_CODE = "ggly_iptv_home";
var uri = "column/iptv_home/iptv_home" + CONFIG.EXT + "?1=1";

var animator, ipAnimator;
var recommend_big = [], recommend_big_interval;			// 保存最大推荐位的数据实属无赖,recommend_big_interval--清理定时器
var Home = {
    userid: Epg.cookie.get("userid"),
    role: Epg.cookie.get("role"),
    orderType: Epg.cookie.get("orderType"),
    carousel_index: Epg.getParamInt("carousel_index", 1),	// 大推荐位轮屏到第几个屏
    idx: 0,												// 为了推荐位滚屏到最后一屏不全时,保存最后一位推荐位排序
    navPrevButtonId: Epg.getParam('navPrevButtonId', ''),
    PicPrevButtonId: 0,
    recommendPrevButtonId: Epg.getParam('recommendPrevButtonId', ''),
    citytypePrevButtonId: Epg.getParam('citytypePrevButtonId', ''),
    cityselectPrevButtonId: Epg.getParam('cityselectPrevButtonId', ''),
    ipPrevButtonId: Epg.getParam('ipPrevButtonId', ''),
    recommendScrollLeft: Epg.getParamInt("recommendScrollLeft", 0),	// recommend推荐位列表scrollLeft值
    spriteType: Epg.cookie.get('spriteType', ''),
    dress: Epg.cookie.get('dress', ''),

    create_recommend_small: function (obj, idx) {	// 两个小推荐位放在一起的推荐位
        var html = '';
        return html;
    },
    create_recommend_middle: function (obj, idx) {	// 一个推荐位放在一起的推荐位

    },
    autoPlay: function () {							// 最大推荐位进行轮播
        Home.carousel_index++;
        Home.carousel_index = Home.carousel_index >= recommend_big[0].length ? 0 : Home.carousel_index;
        var recom_big = document.querySelectorAll('.recommend_big');
        Array.prototype.slice.call(recom_big).forEach(function (value, index) {
            var span = value.getElementsByTagName('span');
            var li = value.getElementsByTagName('li');
            Array.prototype.slice.call(span).forEach(function (value, index) {
                value.className = index === Home.carousel_index ? 'recommend_big_show' : '';
            });
            Array.prototype.slice.call(li).forEach(function (value, index) {
                value.className = index === Home.carousel_index ? 'recommend_dian' : '';
            });
            value.querySelector('.recommend_txt').innerHTML = recommend_big[index][Home.carousel_index].label;
        });
    },
    create_recommend_big: function (obj, idx) {		// 三个大的推荐位放在一起的推荐位

    },
    init_area: function () {// 初始化选择省市区
        var obj1 = {
            id: "back_choosearea_div_id",
            action: Home.back_choosecity,
            focusHandler: Home.ipFocusHandler,
            blurHandler: Home.ipBlurHandler,
            beforeMove: Home.choosecity_back_BeforeMoveHandler,
            up: [],
            down: [],
            focusClass: 'tj',
            autoDirGroup: 4,

        };
        var obj2 = {
            id: "sheng_id",
            action: Home.back_choosecity,
            focusHandler: Home.ipFocusHandler,
            blurHandler: Home.ipBlurHandler,
            beforeMove: Home.city_type_BeforeMoveHandler,
            up: [],
            down: [],
            focusClass: 'typeselect',
            autoDirGroup: 4,

        };
        var obj3 = {
            id: "shi_id",
            action: Home.back_choosecity,
            focusHandler: Home.ipFocusHandler,
            blurHandler: Home.ipBlurHandler,
            beforeMove: Home.city_type_BeforeMoveHandler,
            up: [],
            down: [],
            focusClass: 'typeselect',
            autoDirGroup: 4,

        };
        var obj4 = {
            id: "xuanze_id",
            action: Home.back_choosecity,
            focusHandler: Home.ipFocusHandler,
            blurHandler: Home.ipBlurHandler,
            beforeMove: Home.city_type_BeforeMoveHandler,
            up: [],
            down: [],
            focusClass: 'typeselect',
            autoDirGroup: 4,

        };
        buttons.push(obj1);
        buttons.push(obj2);
        buttons.push(obj3);
        buttons.push(obj4);
        $.post("./js/city.json", {}, function (data) {
            console.log(data);
            city_list = data;
            html = "   <div class=\"choose_list_1\"  id=\"choose_list_1_id\">";
            for (var i = 0; i < city_list.length; i++) {
                html += "<div id=\"choose_item_id" + i + "\" class=\"choose_item\">" + city_list[i].name + "</div>";
                var obj = {
                    id: 'choose_item_id' + i,
                    action: Home.choose_city_item,
                    focusHandler: Home.AreaFocusHandler,
                    blurHandler: Home.AreaBlurHandler,
                    beforeMove: Home.chooseareaBeforeMoveHandler,
                    up: i == 0 ? [] : '',
                    down: '',
                    focusClass: 'select',
                    autoDirGroup: 4,
                    scrollDir: 'y'
                };
                if (i === 0) {
                    obj['left'] = ['ip_first'];
                    obj['restoreScroll'] = true;
                } else {
                    obj['scrollScreen'] = true;
                }
                buttons.push(obj);
            }
            html += "</div>";
            G("choose_list_id").innerHTML = html;
            Epg.autoMakeBtnDir(buttons);
            Epg.btn.init([Epg.getParam('f'), 'choose_item_id0'], buttons, '', false);

            Epg.scrollScreen.init({wrapperId: 'choose_list_id', safePx: 5});
            Epg.scrollScreen.check(Epg.btn.current);
            realFunc1();

        }, "json")

    },
    recommendFocusHandler: function () {								// 推荐位获得焦点

    },
    recommendBlurHandler: function () {								// 推荐位失去焦点
        if ('recommend_first_1' != Epg.btn.previous.id && 'recommend_first_0' != Epg.btn.previous.id) {
            Epg.marquee.stop();
        }
    },
    choosecity_back_BeforeMoveHandler: function (dir, current) {
        if (!isEnableButton && typeof mp != 'undefined') return false;
        if ("down" === dir && !(current.down && current.down.length > 0)) {

            Epg.btn.set(Home.cityselectPrevButtonId || "choose_item_id0");

            return false;
        } else {
            return false;
        }

    },
    chooseareaBeforeMoveHandler: function (dir, current) {
        if ("up" === dir && !(current.up && current.up.length > 0)) {
            Home.cityselectPrevButtonId = current.id;
            Epg.btn.set(Home.citytypePrevButtonId || 'back_choosearea_div_id');
            return false;
        }

    },
    city_type_BeforeMoveHandler: function (dir, current) {			// 推荐位移动前判断事件
        if (!isEnableButton && typeof mp != 'undefined') return false;
        if ("down" === dir && !(current.down && current.down.length > 0)) {
            Home.citytypePrevButtonId = current.id;
            console.log("英藏");
            Epg.btn.set(Home.ipPrevButtonId || "choose_item_id0");

            return false;
        } else if ("up" === dir && !(current.up && current.up.length > 0)) {
            Home.citytypePrevButtonId = current.id;
            console.log("显示");

            Epg.btn.set(Home.navPrevButtonId || "back_choosearea_div_id");
            return false;
        }
    },
    recommendBeforeMoveHandler: function (dir, current) {			// 推荐位移动前判断事件
        if (!isEnableButton && typeof mp != 'undefined') return false;
        if ("down" === dir && !(current.down && current.down.length > 0)) {
            Home.recommendPrevButtonId = current.id;
            console.log("英藏");
            Epg.btn.set(Home.ipPrevButtonId || "tj_type_state_1");
//Hide('top_tuijian_id');
            return false;
        } else if ("up" === dir && !(current.up && current.up.length > 0)) {
            Home.recommendPrevButtonId = current.id;
            console.log("显示");
            //Show('top_tuijian_id');
            Epg.btn.set(Home.navPrevButtonId || "myorder_div_id");
            return false;
        }
    },
    recommendClick: function () {									// 推荐位点击事件
        if (!isEnableButton && typeof mp != 'undefined') return;									// 初始化视频时,按钮点击事件失效
        Home.updateCurrentUri();
        var id = Epg.btn.current.id, tag = Epg.btn.current.tag;
        if ('big' === tag) {											// 专门对大推荐位进行处理
            var index = Epg.btn.current.index;
            Home.isOrder({
                type: recommend_big[index][Home.carousel_index].type,
                code: recommend_big[index][Home.carousel_index].value
            });
        } else if ('recommend_video' === id) {
            if ("free" != Home.orderType) {
                Epg.goMP('column/mp/mp' + CONFIG.EXT + '?method=playFromProgram&pid=' + Play.programId + '&code=' + Play.videoCode);
            } else {
                Epg.go('column/order/order' + CONFIG.EXT + '?source=' + CONFIG.COLUMN_CODE + '&code=' + Play.videoCode);
            }
        } else {
            Home.isOrder({type: Epg.btn.current.type, code: Epg.btn.current.code});
        }
    },
    isOrder: function (recommend) {									// 推荐位等的判断事件
        var type = recommend.type, code = recommend.code;
        if ('album' === type || 'activity' === type || 'column' === type) {
            Home.getActivityOrAlbum(code);
        } else if ('recommend_series' === type) {
            Epg.go('column/subSeries/subSeries' + CONFIG.EXT + '?code=' + code);
        } else {
            if ("free" != Home.orderType) {
                Epg.goMP('column/mp/mp' + CONFIG.EXT + '?method=playVideo&code=' + code);
            } else {
                Epg.go('column/order/order' + CONFIG.EXT + '?source=' + CONFIG.COLUMN_CODE + '&code=' + code);
            }
        }
    },
    getActivityOrAlbum: function (code) {							// 进入活动或者专辑页面
        var postData = {'code': code, 'appVersion': CONFIG.APP_VERSION, 'role': Home.role};
        Epg.postAPI('epg/get', postData, function (data) {
            if (data && data.code === 0) {
                Epg.go(data.epg.path);
            }
        });
    },
    tishiFocusHandler: function () {					// IP形象获得焦点

        G("tishi_span_id").style.display="none";
    },
    tishiBlurHandler: function () {						//	IP形象失去焦点

        G("tishi_span_id").style.display="block";
    },
    ipFocusHandler: function () {					// IP形象获得焦点
        var id = Epg.btn.current.id;
        //G(id).focus();

    },
    inputFocusHandler: function () {
        var id = Epg.btn.current.id;
        //G(id).style.right = "50px";				// 防止IP形象错位
        console.log(id);
        //G(id).focus();



    },
    ipBlurHandler: function () {						//	IP形象失去焦点
        var id = Epg.btn.previous.id;
        //G(id).style.right= "50px";				// 恢复IP形象原始位置
        console.log("光标失去"+id);
        //G(id).blur();
        $("input").attr("disabled",true);
    },

    AreaFocusHandler: function () {					// 选择省市区获得焦点
        var id = Epg.btn.current.id;
        //G(id).style.right = "50px";				// 防止IP形象错位

        G("sheng_id").innerHTML = G(id).innerHTML;
    },
    CityFocusHandler: function () {					// 选择省市区获得焦点
        var id = Epg.btn.current.id;
        //G(id).style.right = "50px";				// 防止IP形象错位
        console.log("CityFocusHandler");
        G("shi_id").innerHTML = G(id).innerHTML;
    },
    xuanze_FocusHandler: function () {					// 选择省市区获得焦点
        var id = Epg.btn.current.id;
        //G(id).style.right = "50px";				// 防止IP形象错位
        console.log("CityFocusHandler");
        G("xuanze_id").innerHTML = G(id).innerHTML;
    },
    AreaBlurHandler: function () {						//	选择省市区获得焦点失去焦点
        var id = Epg.btn.previous.id;
        //G(id).style.right= "50px";				// 恢复IP形象原始位置

    },
    backBeforeMoveHandler: function (dir, current) {	// 返回按钮判断事件
        if (!isEnableButton && typeof mp != 'undefined') return false;
        if ("down" === dir && !(current.down && current.down.length > 0)) {

            Epg.btn.set("input_id1");

            return false;
        } else {
            return false;
        }
    },
    name_BeforeMoveHandler1: function (dir, current) {	//收货人姓名移动前的判断事件

        if (!isEnableButton && typeof mp != 'undefined') return false;
        if ("down" === dir && !(current.down && current.down.length > 0)) {
            //G("ssx_div_id").focus();
            Epg.btn.set("ssx_div_id");

            return false;
        } else if ("up" === dir && !(current.up && current.up.length > 0)) {
            //G("back_div_id").focus();
            Epg.btn.set("back_div_id");
            return false;
        } else if ("right" === dir && !(current.up && current.up.length > 0)) {
            //G("input_id2").focus();
            Epg.btn.set("input_id2");
            return false;
        }
    },
    phone_BeforeMoveHandler2: function (dir, current) {	//收货人姓名移动前的判断事件
        if (!isEnableButton && typeof mp != 'undefined') return false;
        if ("down" === dir && !(current.down && current.down.length > 0)) {
            //G("ssx_div_id").focus();
            Epg.btn.set("ssx_div_id");

            return false;
        } else if ("up" === dir && !(current.up && current.up.length > 0)) {
            //G("back_div_id").focus();
            Epg.btn.set("back_div_id");
            return false;
        } else if ("left" === dir && !(current.up && current.up.length > 0)) {
            //G("input_id1").focus();
            Epg.btn.set("input_id1");
            return false;
        } else {
            return false;
        }
    },
    addr_BeforeMoveHandler: function (dir, current) {	//省市区移动前的判断事件
        if (!isEnableButton && typeof mp != 'undefined') return false;
        if ("down" === dir && !(current.down && current.down.length > 0)) {
            //G("input_id3").focus();
            Epg.btn.set("input_id3");

            return false;
        } else if ("up" === dir && !(current.up && current.up.length > 0)) {
            //G("input_id1").focus();
            Epg.btn.set("input_id1");
            return false;
        } else {
            return false;
        }
    },

    addr_detail_BeforeMoveHandler: function (dir, current) {	//详细地址移动前的判断事件
        if (!isEnableButton && typeof mp != 'undefined') return false;
        if ("down" === dir && !(current.down && current.down.length > 0)) {
            //G("btn_address_commit_id").focus();
            Epg.btn.set("btn_address_commit_id");

            return false;
        } else if ("up" === dir && !(current.up && current.up.length > 0)) {
            //G("ssx_div_id").focus();
            Epg.btn.set("ssx_div_id");
            return false;
        } else {
            return false;
        }
    },
    commit_BeforeMoveHandler: function (dir, current) {	//提交按钮移动前的判断事件
        if (!isEnableButton && typeof mp != 'undefined') return false;
        if ("up" === dir && !(current.up && current.up.length > 0)) {
            Epg.btn.set("input_id3");
            return false;
        } else if ("left" === dir && !(current.up && current.up.length > 0)) {

            Epg.btn.set("left_div_id");
            return false;
        } else {
            return false;
        }
    },
    picture_BeforeMoveHandler: function (dir, current) {	//提交按钮移动前的判断事件
        if (!isEnableButton && typeof mp != 'undefined') return false;
        if ("down" === dir && !(current.up && current.up.length > 0)) {

            if (Home.PicPrevButtonId < 5) {
                Home.PicPrevButtonId++;
                for (var i = 1; i < 6; i++) {
                    G("left_div_id" + i).style.display = "none";
                }
                G("left_div_id" + Home.PicPrevButtonId).style.display = "block";
            }


            return false;
        } else if ("right" === dir && !(current.up && current.up.length > 0)) {
            if (NATURE == 0) {
                Epg.btn.set("input_phone_id");
            } else if (NATURE == 1) {
                Epg.btn.set("focus_btn_1");
            }


            return false;
        } else if ("up" === dir && !(current.up && current.up.length > 0)) {

            if (Home.PicPrevButtonId > 1) {
                Home.PicPrevButtonId--;
                for (var i = 1; i < 6; i++) {
                    G("left_div_id" + i).style.display = "none";
                }
                G("left_div_id" + Home.PicPrevButtonId).style.display = "block";
            }


            return false;
        } else {
            return false;
        }
    },
    ipBeforeMoveHandler: function (dir, current) {	// IP形象移动前的判断事件
        if (!isEnableButton && typeof mp != 'undefined') return false;
        if ("down" === dir && !(current.down && current.down.length > 0)) {

            console.log("ipBeforeMoveHandler英藏");
            Epg.btn.set("buy_num_id");

            return false;
        } else if ("left" === dir && !(current.up && current.up.length > 0)) {

            Epg.btn.set("left_div_id");
            return false;
        } else if ("up" === dir && !(current.up && current.up.length > 0)) {
            Home.ipPrevButtonId = current.id;
            if (NATURE == 0) {
                Epg.btn.set("input_phone_id");
            } else if (NATURE == 1) {
                Epg.btn.set("focus_btn_1");
            }


            return false;
        } else {
            return false;
        }
    },
    ipBeforeMoveHandler1: function (dir, current) {	// IP形象移动前的判断事件
        if (!isEnableButton && typeof mp != 'undefined') return false;
        if ("down" === dir && !(current.down && current.down.length > 0)) {
            Home.navPrevButtonId = current.id;
            console.log("ipBeforeMoveHandler英藏");
            Epg.btn.set("focus_btn_4");

            return false;
        } else if ("up" === dir && !(current.up && current.up.length > 0)) {

            console.log("ipBeforeMoveHandler显示");
            if (NATURE == 0) {
                Epg.btn.set("input_phone_id");
            } else if (NATURE == 1) {
                Epg.btn.set("focus_btn_1");
            }

            return false;
        } else if ("right" === dir && !(current.up && current.up.length > 0)) {

            Epg.btn.set("buy_num_id");
            return false;
        } else {
            return false;
        }
    },
    ipBeforeMoveHandler2: function (dir, current) {	// IP形象移动前的判断事件
        if (!isEnableButton && typeof mp != 'undefined') return false;
        if ("down" === dir && !(current.down && current.down.length > 0)) {
            Home.navPrevButtonId = current.id;
            console.log("ipBeforeMoveHandler英藏");
            Epg.btn.set("focus_btn_4");

            return false;
        } else if ("up" === dir && !(current.up && current.up.length > 0)) {

            console.log("ipBeforeMoveHandler显示");

            if (NATURE == 0) {
                Epg.btn.set("input_phone_id");
            } else if (NATURE == 1) {
                Epg.btn.set("focus_btn_1");
            }
            return false;
        } else if ("left" === dir && !(current.up && current.up.length > 0)) {

            if (buy_num > 1) {
                buy_num--;
                G("buy_num_span_id").innerText = buy_num;
            }
            return false;
        } else if("right" === dir && !(current.up && current.up.length > 0)){

            buy_num++;
            G("buy_num_span_id").innerText = buy_num;

            return false;
        }
    },
    address_Click: function () {
        console.log("IP点击事件");// 地址输入框点击事件
        if (!isEnableButton && typeof mp != 'undefined') return;					// 初始化视频时,按钮点击事件失效
        var domid = Epg.btn.current.id;
        Hide("shop_detail_home_id");
        Show("add_new_address_id");
Home.setinterval();
        G("erweima_img_id").style.backgroundImage="url('"+addressQrCodeImg+"')";
        //Epg.btn.get("back_div_id").focusHandler();
        Epg.btn.init([Epg.getParam('f'), 'back_div_id'], buttons, '', false);
    },
    back_addr: function () {
        console.log(" 返回");

        clearInterval(interval);
        window.history.go(-1);

    },
    commit_order: function () {
        var input_val1 = G("input_id1").value;
        var input_val2 = G("input_id2").value;
        var input_val3 = G("input_id3").value;
        var address = G("ssx_div_id").innerText;
        console.log(address);
        if (input_val1 == "") {
            popup.pop({content: "收货人姓名不能为空！"});
            return false;
        }
        if (input_val2 == "") {
            popup.pop({content: "手机号码不能为空！"});
            return false;
        }
        if (input_val3 == "") {
            popup.pop({content: "详细地址不能为空！"});
            return false;
        }
        $.post(CONFIG.BASEURL + "noLogin/internetTv_addressManager.msp", {
            userId: UserID,
            name: input_val1,
            id:address_id,
            mobile: input_val2,
            proCode: address,
            cityCode: "",
            areaCode: "",
            address: input_val3,
            flag:1,
            isTest: "wondertek",
            uuid: "123"
        }, function (data) {
            console.log(data);
            var retcode = data.retcode;
            if (retcode == 0) {
                //G("addr_input_span_id").innerHTML = input_val1 + " " + input_val2 + "<br/>" +address
                //    + "<br/>" + input_val3;
                //Show("shop_detail_home_id");
                //Hide("add_new_address_id");
                //clearInterval(interval);
                //if (NATURE == 0) {
                //    Epg.btn.init([Epg.getParam('f'), 'input_phone_id'], buttons, '', false);
                //} else if (NATURE == 1) {
                //    Epg.btn.init([Epg.getParam('f'), 'focus_btn_1'], buttons, '', false);
                //}
                //
                //phonenum=input_val2;
                //G("num_div_id").style.top="5rem";
                window.history.go(-2);
            } else {
                var retmsg = data.retmsg;
                popup.pop({content: retmsg});
            }

        }, "json")

    },
    setinterval:function(){
        interval=setInterval(function(){

Home.getNewAddress();
        },3000);

    },

    //地址轮询接口
    getNewAddress:function(){
        $.post(CONFIG.BASEURL + "noLogin/internetTv_getAddressRoll.msp", {
            userId: UserID,
            isTest: "wondertek",
            uuid: "123"
        }, function (data) {

            var retcode = data.retcode;
            var retmsg= data.retmsg;
            if (retcode == 0) {
                var retdata = data.retdata;

               G("input_id1").value=retdata.name;
                G("input_id2").value=retdata.mobile;
                G("input_id3").value=retdata.address;
                G("ssx_div_id").innerText=retdata.proCode;

            }else{
                //popup.pop({content:retmsg});
            }
        }, "json")

    },
    init_detail: function () {


    },
    input_div: function () {
        console.log("弹出软键盘");
        var id = Epg.btn.current.id;
        //G(id).style.right = "50px";				// 防止IP形象错位
        console.log(id);
        //G(id).focus();
        $("#input_id1").attr("disabled",false);
        $("#input_id1").removeAttr("disabled");
        G(id).focus();
    },
    input_div2: function () {
        console.log("弹出软键盘");
        var id = Epg.btn.current.id;
        //G(id).style.right = "50px";				// 防止IP形象错位
        console.log(id);
        //G(id).focus();
        $("#input_id2").attr("disabled",false);
        $("#input_id2").removeAttr("disabled");
        G(id).focus();
    },
    input_div3: function () {
        console.log("弹出软键盘");
        var id = Epg.btn.current.id;
        //G(id).style.right = "50px";				// 防止IP形象错位
        console.log(id);
        //G(id).focus();
        $("#input_id3").attr("disabled",false);
        $("#input_id3").removeAttr("disabled");
        G(id).focus();
    },
    back_choosecity: function () {
        console.log(" 返回");
        Show("add_new_address_id");
        Home.setinterval();
        Hide("shop_detail_home_id");
        Hide("choose_area_id");
        Epg.btn.init([Epg.getParam('f'), 'back_div_id'], buttons, '', false);

    },

    jump_choosecity: function () {
        //Show("choose_area_id");
        //Hide("shop_detail_home_id");
        //Hide("add_new_address_id");
        clearInterval(interval);
        window.location.href="area_choose.html";
        //Epg.removeClass(G("ssx_div_id"), 'btn_focus_tj');
        //Epg.removeClass(G("back_choosearea_div_id"), 'btn_focus_tj');
        ////Epg.btn.init([Epg.getParam('f'), 'back_choosearea_div_id'], buttons, '', false);
        //Home.init_area();
        //Epg.addClass(G("sheng_id"), 'btn_focus_typeselect');
        //Epg.removeClass(G("xuanze_id"), 'btn_focus_typeselect');
        //G("sheng_id").innerHTML = "北京市";
        //G("shi_id").innerHTML = "北京市";
        //G("xuanze_id").innerHTML = "请选择";
    },
    choose_city_item: function () {
        var id = Epg.btn.current.id;
        id = id.slice(id.indexOf('d') + 1, id.length);
        console.log(id);
        Hide("choose_list_1_id");
        var buttons_city = [];
        var obj1 = {
            id: "back_choosearea_div_id",
            action: Home.back_choosecity,
            focusHandler: Home.ipFocusHandler,
            blurHandler: Home.ipBlurHandler,
            beforeMove: Home.choosecity_back_BeforeMoveHandler,
            up: [],
            down: [],
            focusClass: 'tj',
            autoDirGroup: 4,

        };
        buttons_city.push(obj1);
        shengname = city_list[id].name;
        citys = city_list[id].city;

        html = "   <div class=\"choose_list_2\"  id=\"choose_list_2_id\">";
        for (var i = 0; i < citys.length; i++) {
            html += "<div id=\"choose_city_item_id" + i + "\" class=\"choose_item\">" + citys[i].name + "</div>";
            var obj = {
                id: 'choose_city_item_id' + i,
                action: Home.choose_area_item,
                focusHandler: Home.CityFocusHandler,
                blurHandler: Home.AreaBlurHandler,
                beforeMove: Home.chooseareaBeforeMoveHandler,
                up: i == 0 ? [] : '',
                down: '',
                focusClass: 'select',
                autoDirGroup: 4,
                scrollDir: 'y'
            };
            if (i === 0) {
                obj['left'] = ['ip_first'];
                obj['restoreScroll'] = true;
            } else {
                obj['scrollScreen'] = true;
            }
            buttons_city.push(obj);
        }
        html += "</div>";
        G("choose_list_id").innerHTML = html;
        Show("choose_list_2_id");
        Epg.removeClass(G("sheng_id"), 'btn_focus_typeselect');
        Epg.addClass(G("shi_id"), 'btn_focus_typeselect');
        Epg.autoMakeBtnDir(buttons_city);
        Epg.btn.init([Epg.getParam('f'), 'choose_city_item_id0'], buttons_city, '', false);

        Epg.scrollScreen.init({wrapperId: 'choose_list_id', safePx: 5});
        Epg.scrollScreen.check(Epg.btn.current);
        realFunc1();

    },
    choose_area_item: function () {
        var id = Epg.btn.current.id;
        id = id.slice(id.indexOf('d') + 1, id.length);
        console.log(id);
        Hide("choose_list_1_id");
        Hide("choose_list_2_id");
        var buttons_area = [];
        var obj1 = {
            id: "back_choosearea_div_id",
            action: Home.back_choosecity,
            focusHandler: Home.ipFocusHandler,
            blurHandler: Home.ipBlurHandler,
            beforeMove: Home.choosecity_back_BeforeMoveHandler,
            up: [],
            down: [],
            focusClass: 'tj',
            autoDirGroup: 4,

        };
        buttons_area.push(obj1);
        cityname = citys[id].name;
        areas = citys[id].area;

        html = "   <div class=\"choose_list_3\"  id=\"choose_list_3_id\">";
        for (var i = 0; i < areas.length; i++) {
            html += "<div id=\"choose_area_item_id" + i + "\" class=\"choose_item\">" + areas[i] + "</div>";
            var obj = {
                id: 'choose_area_item_id' + i,
                action: Home.choose_qu_item,
                focusHandler: Home.xuanze_FocusHandler,
                blurHandler: Home.AreaBlurHandler,
                beforeMove: Home.chooseareaBeforeMoveHandler,
                up: i == 0 ? [] : '',
                down: '',
                focusClass: 'select',
                autoDirGroup: 4,
                scrollDir: 'y'
            };
            if (i === 0) {
                obj['left'] = ['ip_first'];
                obj['restoreScroll'] = true;
            } else {
                obj['scrollScreen'] = true;
            }
            buttons_area.push(obj);
        }
        html += "</div>";
        G("choose_list_id").innerHTML = html;
        Show("choose_list_3_id");
        Epg.removeClass(G("sheng_id"), 'btn_focus_typeselect');
        Epg.removeClass(G("shi_id"), 'btn_focus_typeselect');
        Epg.addClass(G("xuanze_id"), 'btn_focus_typeselect');
        Epg.autoMakeBtnDir(buttons_area);
        Epg.btn.init([Epg.getParam('f'), 'choose_area_item_id0'], buttons_area, '', false);

        Epg.scrollScreen.init({wrapperId: 'choose_list_id', safePx: 5});
        Epg.scrollScreen.check(Epg.btn.current);
        realFunc1();

    },
    choose_qu_item: function () {

        var id = Epg.btn.current.id;
        id = id.slice(id.indexOf('d') + 1, id.length);
        quname = areas[id];
        console.log(shengname + ";" + cityname + ";" + quname);
        G("ssx_div_id").innerHTML = shengname + cityname  + quname;
        Show("add_new_address_id");
        Home.setinterval();
        Hide("shop_detail_home_id");
        Hide("choose_area_id");

        Epg.btn.init([Epg.getParam('f'), 'ssx_div_id'], buttons, '', false);
        Epg.removeClass(G("back_choosearea_div_id"), 'btn_focus_tj');
    },
    add_Click: function () {
        console.log("sortClick点击事件");//加减件数点击事件
        //var domid = Epg.btn.current.id;
        //buy_num++;
        //G("buy_num_span_id").innerText = buy_num;
    },
    sub_Click: function () {
        console.log("sortClick点击事件");//加减件数点击事件
        //var domid = Epg.btn.current.id;
        //if (buy_num > 1) {
        //    buy_num--;
        //    G("buy_num_span_id").innerText = buy_num;
        //}

    },
    ljgm_click: function () {


    },
    navBeforeMoveHandler: function (dir, current) {	// 导航条移动前的判断事件
        if (!isEnableButton && typeof mp != 'undefined') return false;
        if ("up" === dir && !(current.up && current.up.length > 0)) {

            console.log("ipBeforeMoveHandler显示");
            Epg.btn.set(Home.navPrevButtonId || "buy_num_id");
            return false;
        } else if ("left" === dir && !(current.up && current.up.length > 0)) {

            Epg.btn.set("left_div_id");
            return false;
        } else {
            return false;
        }

    },
    navClick: function () {							// 导航条点击事件
        if (!isEnableButton && typeof mp != 'undefined') return;					// 初始化视频时,按钮点击事件失效
        var code = Epg.btn.current.code;
        if (code === CONFIG.COLUMN_CODE) return;
        Home.updateCurrentUri();
        if ('ggly_iptv_area' === code) {
            location.href = CONFIG.EPG_PATH + 'column/areaPage/areaPage' + CONFIG.EXT + '?source=' + CONFIG.COLUMN_CODE;
        } else if ('ggly_iptv_more' === code) {
            location.href = CONFIG.EPG_PATH + 'column/morePage/morePage' + CONFIG.EXT + '?source=' + CONFIG.COLUMN_CODE;
        } else if ("nav_order" === code) {
            if ("month" == Home.orderType) {
                Epg.tip('您是已订购用户，无需重复订购');
            } else {
                Epg.go('column/order/order' + CONFIG.EXT);
            }
        } else if ("nav_search" === code) {
            Epg.go('column/search/search' + CONFIG.EXT);
        } else if ("nav_history" === code) {
            Epg.go('history' + CONFIG.EXT + '?isPlay=true');
        } else if ("nav_fav" === code) {
            Epg.go('column/fav/seriesFav' + CONFIG.EXT + '?isPlay=true');
        } else {
            location.href = CONFIG.EPG_PATH + 'column/secondPage/secondPage' + CONFIG.EXT + '?code=' + code + '&source=' + CONFIG.COLUMN_CODE;
        }
    },
    updateCurrentUri: function () {
        CONFIG.CURRENT_URI = uri + '&navPrevButtonId=' + Home.navPrevButtonId + '&recommendPrevButtonId=' + Home.recommendPrevButtonId + '&ipPrevButtonId=' + Home.ipPrevButtonId +
            '&recommendScrollLeft=' + Home.recommendScrollLeft + '&carousel_index=' + Home.carousel_index;
    },
    initAnimator: function () {						// 初始化左下角动画形象

    },
    animatorStart: function () {						// 动画形象摆动方法
        var index = 0;
        ipAnimator = new Animator(100 * Home.ipLen, function (p) {
            index = Math.floor(p * Home.ipLen);
            if (index >= Home.ipLen) {
                index = 0;
            }
            G("animators").scrollTop = index * 215;
        });
        ipAnimator.start(function () {
            Home.animatorStart();
        });
    },
    ipSelectAction: function () {					// IP形象选择点击事件
        var id = Epg.btn.current.id;

    }
};

var buttons = [];
var buy_num = 1;

var obj5 = {
    id: 'back_div_id',
    action: Home.back_addr,
    focusHandler: Home.ipFocusHandler,
    blurHandler: Home.ipBlurHandler,
    beforeMove: Home.backBeforeMoveHandler,
    up: [],
    down: [],
    focusClass: 'tj',
    autoDirGroup: 5
};

var obj6 = {
    id: 'input_id1',
    action: Home.input_div,
    focusHandler: Home.inputFocusHandler,
    blurHandler: Home.ipBlurHandler,
    beforeMove: Home.name_BeforeMoveHandler1,
    up: [],
    down: [],
    left: '',
    focusClass: 'tj',
    autoDirGroup: 5
};
var obj7 = {
    id: 'input_id2',
    action: Home.input_div2,
    focusHandler: Home.inputFocusHandler,
    blurHandler: Home.ipBlurHandler,
    beforeMove: Home.phone_BeforeMoveHandler2,
    up: [],
    down: [],
    right: '',
    focusClass: 'tj',
    autoDirGroup: 5
};
var obj8 = {
    id: 'ssx_div_id',
    action: Home.jump_choosecity,
    focusHandler: Home.ipFocusHandler,
    blurHandler: Home.ipBlurHandler,
    beforeMove: Home.addr_BeforeMoveHandler,
    up: [],
    down: [],
    focusClass: 'tj',
    autoDirGroup: 5
};
var obj9 = {
    id: 'input_id3',
    action: Home.input_div3,
    focusHandler: Home.inputFocusHandler,
    blurHandler: Home.ipBlurHandler,
    beforeMove: Home.addr_detail_BeforeMoveHandler,
    up: [],
    down: [],
    focusClass: 'tj',
    autoDirGroup: 5
};
var obj10 = {
    id: 'btn_address_commit_id',
    action: Home.commit_order,
    focusHandler: Home.ipFocusHandler,
    blurHandler: Home.ipBlurHandler,
    beforeMove: Home.commit_BeforeMoveHandler,
    up: [],
    down: [],
    focusClass: 'tj',
    autoDirGroup: 5
};


buttons.push(obj5);

buttons.push(obj6);
buttons.push(obj7);
buttons.push(obj8);
buttons.push(obj9);
buttons.push(obj10);

function back() {

        window.history.go(-1);



}

// 简单的节流函数
function throttle(func, wait, mustRun) {
    var timeout, startTime = new Date();
    return function () {
        var context = this, args = arguments, curTime = new Date();
        clearTimeout(timeout);
        // 如果达到了规定的触发时间间隔，触发 handler
        if (curTime - startTime >= mustRun) {
            //func.apply(context,args);
            func();
            startTime = curTime;
            // 没达到触发间隔，重新设定定时器
        } else {
            timeout = setTimeout(func, wait);
        }
    };
};
// 实际想绑定在 scroll 事件上的 handler
function realFunc(wrapperId) {
    wrapperId = wrapperId || Epg.scroll.config.wrapperId;
    var iScrollLeft = G(wrapperId).scrollLeft;
    var iClientLeft = G(wrapperId).getBoundingClientRect().left + iScrollLeft;
    var iClientRight = G(wrapperId).offsetWidth + iClientLeft;
    var btns = G(wrapperId).querySelectorAll("[data-epg-btn]");
    for (var i = 0; i < btns.length; i++) {
        var obj = btns[i];
        // 加载过了的就不需要加载了
        if (!Epg.hasClass(obj, "loaded")) {
            var iLeft = Epg.getAbsolutePosition(obj).left;
            var iRight = iLeft + obj.offsetWidth;
            if ((iLeft > iClientLeft && iLeft < iClientRight) || (iRight > iClientLeft && iRight < iClientRight)) {
                obj.style.backgroundImage = 'url(' + obj.getAttribute("data-url") + ')';
                Epg.addClass(obj, "loaded");
            }
        }
    }
}
// 实际想绑定在 scroll 事件上的 handler
function realFunc1(wrapperId) {
    wrapperId = wrapperId || Epg.scrollScreen.config.wrapperId;
    var iScrollTop = G(wrapperId).scrollTop;
    var iClientTop = G(wrapperId).getBoundingClientRect().top + iScrollTop;
    var iClientBottom = G(wrapperId).offsetHeight + iClientTop;
    var btns = document.querySelectorAll("[data-epg-btn]");
    for (var i = 0; i < btns.length; i++) {
        var obj = btns[i];
        // 加载过了的就不需要加载了
        if (!Epg.hasClass(obj, "loaded")) {
            var iTop = Epg.getAbsolutePosition(obj).top;
            var iBottom = iTop + obj.offsetHeight;
            if ((iTop > iClientTop && iTop < iClientBottom) || (iBottom > iClientTop && iBottom < iClientBottom)) {
                obj.style.backgroundImage = 'url(' + obj.getAttribute("data-url") + ')';
                Epg.addClass(obj, "loaded");
            }
        }
    }
}

// 实际想绑定在 scrollTop 事件上的 handler
function realFuncTop(wrapperId) {
    var iScrollTop = G(wrapperId).scrollTop;
    var iClientTop = G(wrapperId).getBoundingClientRect().top + iScrollTop;
    var iClientBottom = G(wrapperId).offsetHeight + iClientTop;

    var iClientTop0 = iClientTop - 2 * G(wrapperId).offsetHeight;
    var iClientBottom0 = iClientBottom - 2 * G(wrapperId).offsetHeight;

    var iClientTop2 = iClientTop + 2 * G(wrapperId).offsetHeight;
    var iClientBottom2 = iClientBottom + 2 * G(wrapperId).offsetHeight;

    var btns = G(wrapperId).querySelectorAll("[data-epg-btn]");
    console.log("btns:" + btns.length);
    for (var i = 0; i < btns.length; i++) {
        var obj = btns[i];
        // 加载过了的就不需要加载了
        if (!Epg.hasClass(obj, "loaded")) {
            var iTop = Epg.getAbsolutePosition(obj).top;
            var iBottom = iTop + obj.offsetHeight;
            if ((iTop >= iClientTop && iTop <= iClientBottom) || (iBottom >= iClientTop && iBottom <= iClientBottom)) {
                obj.style.backgroundImage = 'url(' + obj.getAttribute("data-url") + ')';
                Epg.addClass(obj, "loaded");
            } else if ((iTop >= iClientTop0 && iTop <= iClientBottom0) || (iBottom >= iClientTop0 && iBottom <= iClientBottom0)) {
                obj.style.backgroundImage = 'url(' + obj.getAttribute("data-url") + ')';
                Epg.addClass(obj, "loaded");
            } else if ((iTop >= iClientTop2 && iTop <= iClientBottom2) || (iBottom >= iClientTop2 && iBottom <= iClientBottom2)) {
                obj.style.backgroundImage = 'url(' + obj.getAttribute("data-url") + ')';
                Epg.addClass(obj, "loaded");
            }
        }
    }
}
function init() {
var address=localStorage.getItem("address");
if(null!=address){
    G("ssx_div_id").innerText=address;
    //localStorage.removeItem('address');
}

    G("erweima_img_id").style.backgroundImage="url('"+addressQrCodeImg+"')";

    Epg.autoMakeBtnDir(buttons);
    Epg.btn.init([Epg.getParam('f'), 'input_id1'], buttons, '', false);



}
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = decodeURI(window.location.search).substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return 1;
}

var addressQrCodeImg=getQueryString('addressQrCodeImg');
var sort = 1;//1-智能排序；2-人气（点击量）排序；3-销量排序；

var city_list = [];//城市选择-省
var citys = [];//市
var areas = [];
var shengname = "";
var cityname = "";
var quname = "";
var NATURE = 0;

var interval=null;
var phonenum="";
var address_id="";

var UserID = localStorage.getItem("UserID");
console.log("window.UserID:::" + UserID);
$(function(){



    show_loading();
    window.method = "playFromProgram";
    Epg.key.init();
    Epg.key.set({
        KEY_BACK: 'back()',
        KEY_5:'',
        KEY_ENTER: 'Epg.Button.click()',			//确定键
        KEY_LEFT: 'Epg.Button.move("left")',		//左键
        KEY_RIGHT: 'Epg.Button.move("right")',		//右键
        KEY_UP: 'Epg.Button.move("up")',			//上键
        KEY_DOWN: 'Epg.Button.move("down")',		//下键

        KEY_DELETE: 'back()',


        EVENT_MEDIA_END: null,
        EVENT_MEDIA_ERROR: function(){
            isEnableButton = true;					// 视频初始化已完成,标识按钮可用
            return Epg.tip("啊哦，视频播放错误了-_-!");
        }
    });
    Epg.key.set({
        KEY_VOL_UP: 'Epg.Mp.volUp()',
        KEY_VOL_DOWN: 'Epg.Mp.volDown()'
    });
    if (Home.recommendScrollLeft > 0) {				// 如果推荐位发生了滚动,补全空白处
        Epg.addClass(G("home_wrapper"), "home_wrapper");
    }


    init();
    Home.setinterval();
    window.onload = function () {
        stop_loading();

    }

})

